package com.ljpz.web.controller;

import com.ljpz.common.service.RedisService;
import com.ljpz.web.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 接受商品id ，
 *
 * 删除对应的缓存数据
 * Created by liujunchen on 2016/12/19.
 */
@RequestMapping("item/cache")
@Controller
public class ItemCacheController {
    @Autowired
    private RedisService redisService   ;
    @RequestMapping(value = "{itemId}",method = RequestMethod.POST)
    public ResponseEntity<Void>deleteCache(@PathVariable("itemId")Long itemId ){
        try {
            String key =  ItemService.REDIS_KEYS+itemId  ;
            this.redisService.del(key) ;
            return   ResponseEntity.status(HttpStatus.NO_CONTENT).build() ;
        } catch (Exception e) {
                e.printStackTrace();
        }
        return  ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build() ;
    }
}
